<?php
namespace app\common\library\notice;
use EasyWeChat\Factory;
/**
 * 微信小程序的订阅消息
 *
 * @author LCY <409028735@qq.com>
 */
class WechatSubscribe{
    
    public static function send($params = []){
        try{
            $config = config('wechat.mini');
            $app = Factory::miniProgram($config);

            $data = [
                'template_id' => $params['template_id'], // 所需下发的订阅模板id
                'touser' => $params['openid'],     // 接收者（用户）的 openid
                'page' => $params['page'],       // 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。
                'data' => [         // 模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }
                    'date01' => [
                        'value' => '2019-12-01',
                    ],
                    'number01' => [
                        'value' => 10,
                    ],
                ],
            ];
            
            $res = $app->subscribe_message->send($data);


            return true;
        }catch(\Exception $e){
            recordExceptionInfo($e);
            return $e->getMessage();
        }
       

    }
    
}